from allpairspy import AllPairs

from api_py.enums.cookie import Cookie
from api_py.generate_case.template import template_case
from api_py.utils.file_sys import write_json

page = [
    {"value": 0, "description": "页码参数为0"},
    {"value": "1", "description": "页码参数为1"},
    {"value": "10", "description": "页码参数为10"},
    {"value": "abc", "description": "页码参数不合法"},
]

size = [
    {"value": 1, "description": "条目参数为1"},
    {"value": 10, "description": "条目参数为10"},
    {"value": "abc", "description": "条目参数不合法"},
]


name = [
    {"value": "", "description": "名字长度为0"},
    {"value": "counselor", "description": "名字合法"},
    {"value": "counselor_123456789", "description": "名字长度超过15"},
]

department = [
    {"value": "", "description": "部门参数为空"},
    {"value": "department", "description": "合法部门参数"},
    {"value": "华东师范大学", "description": "合法部门参数"},
    {"value": "@@@；；😀", "description": "部门为特殊字符"},
]

gender = [
    {"value": "", "description": "性别参数为空"},
    {"value": "男", "description": "合法性别参数"},
    {"value": "女", "description": "合法性别参数"},
    {"value": "无性别", "description": "非法性别参数"},
]

phoneNumber = [
    {"value": "", "description": "电话参数为空"},
    {"value": "159", "description": "合法电话参数"},
    {"value": "phoneNumber", "description": "非法电话参数"},
]

cookies = [
    {"value": Cookie.ADMIN_COOKIE.value, "description": "管理员登录"},
    {"value": Cookie.SUPERVISOR_COOKIE.value, "description": "督导登录"},
    {"value": Cookie.COUNSELOR_COOKIE.value, "description": "咨询师登录"},
    {"value": Cookie.WEIXIN_COOKIE.value, "description": "微信访客登录"},
    {"value": Cookie.NULL_COOKIE.value, "description": "未登录"},
    {"value": Cookie.ERROR_COOKIE.value, "description": "其他Cookie"},
]

params = [
    {"value": 0, "description": "页码参数为0"},
    {"value": "10", "description": "条目参数为10"},
    {"value": "counselor", "description": "名字合法"},
    {"value": "department", "description": "合法部门参数"},
    {"value": "女", "description": "合法性别参数"},
    {"value": "159", "description": "合法电话参数"},
]



def case10_2_user_ms_counselor_list(api_type):
    json_result = {}
    parameters = [page, size, name, department, gender, phoneNumber]
    i = 0

    # 检测数据格式的用例
    for pairs in AllPairs(parameters):
        case = template_case()
        request = case["request"]

        # 设置请求体参数
        wrap_param(request, pairs)
        # 设置请求头cookie
        request["headers"]["Cookie"] = cookies[0]

        json_result[i] = case
        i += 1

    # 检查用户权限的用例
    for cookie in cookies:
        case = template_case()
        request = case["request"]
        # 设置请求体参数
        wrap_param(request, params)

        # 设置请求头cookie
        request["headers"]["Cookie"] = cookie

        json_result[i] = case
        i += 1

    write_json(api_type.value[0]["file_name"], json_result)


def wrap_param(request, params):
    request["params"]["page"] = params[0]
    request["params"]["size"] = params[1]
    request["params"]["name"] = params[2]
    request["params"]["department"] = params[3]
    request["params"]["gender"] = params[4]
    request["params"]["phoneNumber"] = params[5]